#include "YouwantWidget.h"
#include "ui_YouwantWidget.h"

#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGroupBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QTextEdit>
#include <QHBoxLayout>
#include <QVBoxLayout>

// ---
#include <YouwantDeclar>
#include <QApplication>
#include <QClipboard>

YouwantWidget::YouwantWidget(QWidget *parent) : BaseWidget(parent)
, ui(new Ui::YouwantWidget)
{

    ui->setupUi(this);

// 模板动作类型：
    QComboBox *actionCombo = ui->actionCombo;
    QComboBox *actionComboType = ui->actionComboType;

// 模板描述标签：
    QLineEdit *labelEdit = ui->labelEdit;

// 模板描述细节：
    QLineEdit *detailEdit = ui->detailEdit;

// 模板描述类别：
    QLineEdit *typesEdit = ui->typesEdit;

// 模板描述动作：
    QPushButton *copyBtn = ui->copyBtn;

// shell 指令编写部分
    // -- 编辑框
    QTextEdit *scriptEdit = ui->scriptEdit;


    connect(copyBtn, &QPushButton::clicked, [=](){
        YouwantDeclar declar;
        declar.setLabel(actionCombo->currentData().toString().replace("{}", labelEdit->text().trimmed()));
        declar.setDetail(actionCombo->currentData().toString().replace("{}", detailEdit->text().trimmed()));
        declar.setType(typesEdit->text().trimmed());
        declar.setShellCommands(scriptEdit->toPlainText().trimmed().split("\n"));

        QClipboard *clipboard = QApplication::clipboard();
        clipboard->setText(declar.toJson());
    });
}
